Ext.define('FamilyInfo', {
    extend: 'Ext.data.Model',
    fields: [
        "Id"
		, "KinShip"   //亲属关系
		, "Name"   //姓名
		, "Birthday"   //生日
		, "Identification"   //证件
		, "EmpId"   //员工Id
        , "EmpName"   //员工姓名
    ],
    idProperty: "Id"
});

Ext.define('SHApp.EmployeeInfo.FamilyInfo.Grid', {
    extend: 'BLBTSystem.grid',
    alias: 'shapp.employeeinfo.grid',
    requires: ['SHApp.EmployeeInfo.FamilyInfo.Form'],
    txtKinShipID: 'txtKinShip',
    txtNameID: 'txtName',
    dataModel: "FamilyInfo",
    dataUrl: "api/familyinfo?format=json",
    empId: "",
    empName: "",
    initComponent: function () {
        var me = this;
        Ext.apply(this);
        me.btnAddID += me.id;
        me.btnEditID += me.id;
        me.btnDeleteID += me.id;
        me.txtKinShipID += me.id;
        me.txtNameID += me.id;
        this.creatTbar();
        this.creatColumns();
        this.callParent(arguments);
        this.checkBtnPermission(me.pvalue);
    },
    creatColumns: function () {
        var me = this;
        me.columns = [
            {
                text: "Id",
                flex: 1,
                dataIndex: 'Id',
                sortable: false,
                hidden: true
            }, {
                text: "亲属关系",
                width: 100,
                dataIndex: 'KinShip',
                sortable: true
            }, {
                text: "姓名",
                width: 100,
                dataIndex: 'Name',
                sortable: true
            }, {
                text: "生日",
                width: 100,
                dataIndex: 'Birthday',
                sortable: true,
                renderer: formatDate
            }, {
                text: "证件",
                width: 200,
                dataIndex: 'Identification',
                sortable: true
            }, {
                text: "员工Id",
                width: 100,
                dataIndex: 'EmpId',
                sortable: true,
                hidden: true
            }
		]
    },
    creatTbar: function () {
        var me = this;
        me.tbar = [
		     Ext.create("BLBTSystem.CmbYesNo", {
		         fieldLabel: "亲属关系",
		         fields: ["text"],
		         data: [["父亲"], ["母亲"], ["儿女"], ["兄弟姐妹"]],
		         valueField: "text",
		         displayField: "text",
		         name: "KinShip",
		         value: "父亲",
		         maxLength: 50,
		         id: me.txtKinShipID,
		         labelWidth: 60,
		         width: 180
		     }), {
		         xtype: 'textfield',
		         disabled: false,
		         fieldLabel: '姓名:',
		         name: 'Name',
		         id: me.txtNameID,
		         labelWidth: 40,
		         width: 160
		     }, ' ', {
		         xtype: 'button',
		         text: '查询',
		         iconCls: 'icon-btn-search',
		         handler: function () {
		             me.clearFilters();
		             me.addFilter("EmpId", me.empId);
		             var vKinShip = me.down("#" + me.txtKinShipID).getValue();
		             if (vKinShip && vKinShip.length > 0) {
		                 me.addFilter("KinShip", vKinShip);
		             }
		             var vName = me.down("#" + me.txtNameID).getValue();
		             if (vName && vName.length > 0) {
		                 me.addFilter("Name", vName);
		             }
		             me.loadByFilter();
		         }
		     }, '->', {
		         xtype: 'button',
		         text: '添加',
		         id: me.btnAddID,
		         iconCls: 'icon-btn-add',
		         handler: function () {
		             var win = me.getForm('SHApp.EmployeeInfo.FamilyInfo.Form');
		             win.loadRecord(new FamilyInfo({ Id: null, KinShip: "父亲", EmpId: me.empId, EmpName: me.empName }));
		             win.Show("添加");
		         }
		     }, ' ', {
		         xtype: 'button',
		         disabled: true,
		         id: me.btnEditID,
		         text: '修改',
		         iconCls: 'icon-btn-edit',
		         handler: function () {
		             var rs = me.getSelectionModel().getSelection();
		             if (rs) {
		                 if (rs.length > 0) {
		                     rs[0].data.Birthday = formatDate(rs[0].data.Birthday);
		                     me.EditData(me.getForm('SHApp.EmployeeInfo.FamilyInfo.Form'));
		                 }
		             }
		         }
		     }, ' ', {
		         xtype: 'button',
		         disabled: true,
		         id: me.btnDeleteID,
		         text: '删除',
		         iconCls: 'icon-btn-delete',
		         handler: function () {
		             me.DeleteData();
		         }
		     }
        ]
    }
});

